/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gui.event.khachhang;

import control.khachhang.KHMainPanel_ctrl;
import control.khachhang.KHTimKiem_Dialog_Ctrl;
import gui.event.ulti.Util;
import gui.khachhang.KHChiTiet_Dialog;
import gui.khachhang.KHSaoLuu_Dialog;
import gui.khachhang.KHSuaThongTin_Dialog;
import java.awt.print.PrinterException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import model.entity.KhachHang;

/**
 *
 * @author nv_ca@live.com
 */
public class KHTimKiemDlg_evt {
    
    public static final void btnTimKiemActionPerformed(JTextField txtTimTheoMaKH,JTable tblKhachHang) {
        //TODO Tổng hợp điều kiện và query, sau đó hiển thị lên table
//        JOptionPane.showMessageDialog(null, "Found");
        
        KHTimKiem_Dialog_Ctrl.timKiemTheotenKH(txtTimTheoMaKH, tblKhachHang);
        tblKhachHang.resetKeyboardActions();
    }
    
    public static final void btnSaoLuuActionPerformed() {
        //TODO Lựa chọn các index trên table sau đó chuyển qua dialog sao lưu
        KHSaoLuu_Dialog khSaoLuuDlg = new KHSaoLuu_Dialog(null, true);
        khSaoLuuDlg.setLocationRelativeTo(null);
        khSaoLuuDlg.setVisible(true);
    }
    
    public static final void btnSuaActionPerformed(JTable table) {
        //TODO chọn một đối tượng và mở lên dialog sửa
            //pre-condition: selected index = 1
        KhachHang kh = KHMainPanel_ctrl.selectRow(table);
        KHSuaThongTin_Dialog khSuaThongTin = new KHSuaThongTin_Dialog(table, null, true);
        khSuaThongTin.getTxtMaKH().setText(""+kh.getKhMa());
        khSuaThongTin.getTxtHo().setText(""+kh.getKhHo());
        khSuaThongTin.getTxtTen().setText(""+kh.getKhTen());
        khSuaThongTin.getTxtSoDT().setText(""+kh.getKhSdt());
        khSuaThongTin.getjDateChooser1().setDate(kh.getKhNgaySinh());
        khSuaThongTin.getTxtDiaChi().setText(""+kh.getKhDiaChi());
        khSuaThongTin.getTaGhiChu().setText(""+kh.getKhGhiChu());
        khSuaThongTin.setLocationRelativeTo(null);
        khSuaThongTin.setVisible(true);
    }
    
    public static final void btnChiTietActionPerformed(JTable table) {
        //TODO chọn một đối tượng và mở lên dialog chi tiết
            //pre-condition: selected index = 1
        KhachHang kh = KHMainPanel_ctrl.selectRow(table);
        KHChiTiet_Dialog khChiTietDlg = new KHChiTiet_Dialog(null, true);
        khChiTietDlg.getTxtMaKH().setText(""+kh.getKhMa());
        khChiTietDlg.getTxtHoVaTen().setText(""+kh.getKhHo()+kh.getKhTen());
        khChiTietDlg.getTxtSDT().setText(""+kh.getKhSdt());
        khChiTietDlg.getTxtDiaChi().setText(""+kh.getKhDiaChi());
        khChiTietDlg.getTxtGioiTinh().setText(""+kh.getKhGioiTinh());
        KHMainPanel_ctrl.loadVatNuoiTheoMaKH(khChiTietDlg.getTblVatNuoi(), kh.getKhMa());
        khChiTietDlg.setLocationRelativeTo(null);
        khChiTietDlg.setVisible(true);
    }
    
    public static final void btnInActionPerformed(JTable table) {
        try {
            table.print();
        } catch (PrinterException ex) {
            Logger.getLogger(KHTimKiemDlg_evt.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static final void btnCloseActionPerformed(JDialog dlg) {
        dlg.dispose();
    }
    
    public static final void enableListRadioButtons(List<JComponent> components) {
        Util.enableListComponents(components);
    }
    
    public static final void disbleListRadioButtons(List<JComponent> components) {
        Util.disableListComponents(components);
    }
}
